<script>
	import {
		getUrlParams
	} from './util/util.js'
    import {bindSpread} from '@/api/user.js'
	export default {
		
		onLaunch: function(option) {


			let val = option.query
			console.log(">>>>进了", JSON.stringify(val))
			if (val['type'] === 'spread' && val["uid"]) {
				console.log(">>>>进了444", JSON.stringify(val))
				this.$store.commit("SETSPREADUID", val["uid"])
			}

			let that = this;

			if (option.query.hasOwnProperty('scene')) {
				// switch (option.scene) {
				// 	//扫描小程序码
				// 	case 1047:

				// 		//that.globalData.code = val.pid === undefined ? val : val.pid;
				// 		break;
				// 	//长按图片识别小程序码
				// 	case 1048:
				// 		that.globalData.code = option.query.scene;
				// 		break;
				// 	//手机相册选取小程序码
				// 	case 1049:
				// 		that.globalData.code = option.query.scene;
				// 		break;
				// 	//直接进入小程序
				// 	case 1001:
				// 		that.globalData.spid = option.query.scene;
				// 		break;
				// }

				let val = decodeURIComponent(option.query.scene)
				val = getUrlParams(val)
				if (val['id']) {
					that.$store.commit("SETPRODUCTID", val['id'])
				}


				if (val['type'] === 'spread' && val["uid"]) {
					console.log('>ddd1111111', JSON.stringify(val))
					that.$store.commit("SETSPREADUID", val["uid"])

					// if (val['action'] == 'push') {
					// 	console.log('...action', val['action'])
					// 	this.$store.commit("SETACTION", "push")
					// } else {
					// 	this.$store.commit("SETACTION", "none")
					// }
				}


			}
			console.log('App Launch');
					
				
		},
		onShow: function() {
			console.log('App Show')
				
				let spreadUid = this.$store.getters.spreadUid
				
				if(spreadUid && this.$store.getters.isLogin){
					this.$store.dispatch("USERINFO", false ).then((res) => {
						 if(res.spreadUid==0){
							 bindSpread({spreadUid:spreadUid}).then(res=>{
								 if(res.code==200){
									 this.$store.dispatch("USERINFO", true ).then(()=>{})
								 }
								 console.log("res>>>>>>>>>>>>>>>>>>>>>>>>>绑定结果",res)
							 })
						 }
					});
				}
				
			
				const updateManager = uni.getUpdateManager();
				
				// 检查小程序是否有新版本发布
				updateManager.onCheckForUpdate(function (res) {
				  // 请求完新版本信息的回调
				  
				  console.log("1111",res.hasUpdate);
				});
				
				// 小程序有新版本，则静默下载新版本，做好更新准备
				updateManager.onUpdateReady(function (res) {
					console.log('更新',111);
				  uni.showModal({
				    title: '更新提示',
				    content: '新版本已经准备好，点击确定重新启动',
					showCancel:false,
				    success(res) {
				      if (res.confirm) {
				        // 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
				        updateManager.applyUpdate();
				      }
				    }
				  });
				
				});
				
				updateManager.onUpdateFailed(function (res) {
				  
				  // 新的版本下载失败
				  uni.showModal({
				    title: '新版本下载失败，请您删除当前小程序，重新搜索打开哟~',
				    
				  });
				  
				});
							
					
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style lang="scss">
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "uview-ui/index.scss";

	.u-flex {
		display: flex;
		flex-direction: row;
		align-items: center;
	}

	/* 换行 */
	.u-flex-wrap {
		flex-wrap: wrap;
	}

	/* 不换行 */
	.u-flex-nowrap {
		flex-wrap: nowrap;
	}

	.u-col-top {
		align-items: flex-start;
	}

	.u-col-center {
		align-items: center;
	}

	/* 顶部对齐 */
	.u-col-top {
		align-items: flex-start;
	}

	/* 底部对齐 */
	.u-col-bottom {
		align-items: flex-end;
	}

	/* 左边对齐 */
	.u-row-left {
		justify-content: flex-start;
	}

	/* 水平居中 */
	.u-row-center {
		justify-content: center;
	}

	/* 右边对齐 */
	.u-row-right {
		justify-content: flex-end;
	}

	/* 水平两端对齐，项目之间的间隔都相等 */
	.u-row-between {
		justify-content: space-between;
	}

	/* 水平每个项目两侧的间隔相等，所以项目之间的间隔比项目与父元素两边的间隔大一倍 */
	.u-row-around {
		justify-content: space-around;
	}

	.u-flex-1 {
		flex: 1;
	}

	.u-flex-2 {
		flex: 2;
	}

	.u-flex-3 {
		flex: 3;
	}

	.p-20 {
		padding: 20rpx;
	}

	.p-l-20 {
		padding-left: 20rpx;
	}

	.p-r-20 {
		padding-right: 20rpx;
	}

	.m-t-20 {
		margin-top: 20rpx;
	}

	.m-b-20 {
		margin-bottom: 20rpx;
	}

	.m-l-20 {
		margin-left: 20rpx;
	}

	.m-r-20 {
		margin-right: 20rpx;
	}

	.u-text-center {
		text-align: center;
	}

	.u-text-right {
		text-align: right;
	}

	.wm_weight_flod {
		font-weight: 550;
	}

	.wm_color_grey {
		color: #8F8F94;
	}

	.wm_color_red {
		color: #aa0000;
	}

	.wm_color_white {
		color: #FFFFFF;
	}

	.wm_color_black {
		color: #0f0f0f;
	}

	.f-30 {
		font-size: 30rpx;
	}

	.content {

		height: 100%;

	}

	.u-font-30 {
		font-size: 30rpx;
	}

	.u-font-32 {
		font-size: 32rpx;
	}

	.u-font-34 {
		font-size: 34rpx;
	}

	.u-font-36 {
		font-size: 36rpx;
	}

	.footer {
		position: fixed;
		bottom: 0;
		width: 100%;
	}

	.status_bar {
		height: var(--status-bar-height);
		width: 100%;
	}

	.wm_bg_white {
		background-color: #FFFFFF;
	}

	.bg-img {
		background-image: url('https://ymjcos.weimahl.com/image/admin/2023/07/28/fa78f724812940ffa9653a16a04b23f88yo23a1qft.png');
		background-size: 100% 100%;
		height: 100%;
	}
	
	.center-bg {
		background-image: url('https://ymjcos.weimahl.com/image/admin/2023/07/28/20f387bd47454ce09fbd4e57ba80d5b0tzn1z1blzd.png');
		background-size: 100% 100%;
	}
	
	.store-bg {
		background-image: url('https://ymjcos.weimahl.com/image/admin/2023/07/28/111a54e62ec14a849eb2b93ceb7e448clab3429ba5.png');
		background-size: 100% 100%;
	}
</style>
